package smecta.client.print.service;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import smecta.client.print.domain.ScpProductPropertyValuelist;
import smecta.client.print.mapper.ScpProductPropertyValuelistMapper;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ScpProductPropertyValuelistService extends BaseService<ScpProductPropertyValuelist> {

    @Autowired
    private ScpProductPropertyValuelistMapper scpProductPropertyValuelistMapper;

    public List<ScpProductPropertyValuelist> getListByCode(String code){
        if (StringUtils.isBlank(code)){
            return new ArrayList<>();
        }
        Example example = new Example(ScpProductPropertyValuelist.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("code",code);
        return selectByExample(example);
    }

    public List<String> getValueListByCode(String code){
        List<ScpProductPropertyValuelist> listByCode = getListByCode(code);
        return listByCode.stream().map(ScpProductPropertyValuelist::getValue).collect(Collectors.toList());
    }

}
